package com.fz.mybatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;

/**
 * Created by bai on 2017/6/23.
 */
public class DbHelper {
    private SqlSessionFactory sf;
    private SqlSession session;
    public DbHelper(){
        try {
            this.sf = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml"));
            this.session = this.sf.openSession();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public SqlSession getSession(){
        return this.session;
    }
}
